<?php

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\AdminRole\AdminRoleRequest;
use App\Models\AdminAction;
use App\Models\AdminRole;
use Gate;
use App\Exceptions\Admin\PermissionDeniedException;

class AdminRoleController extends Controller
{

    public function admin_role_gate()
    {
        if (!Gate::allows('user','')) {
            throw new PermissionDeniedException();
        }//end if()

    }//end func __construce()

    /**
     * 管理员列表
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $this->admin_role_gate();

        $adminRole = AdminRole::paginate(10);
        return view('admin.admin_role.index',compact(['adminRole']));
    }

    public function create(AdminRole $adminRole){

        $this->admin_role_gate();

        $acls = config('acl');

        return view('admin.admin_role.create',compact(['adminRole','acls']));
    }

    public function store(AdminRoleRequest $adminRoleRequest,AdminRole $adminRole){

        $this->admin_role_gate();

        $adminRole->create($adminRoleRequest->all());
        return Redirect('admin/admin_role');

    }

    public function edit($id){

        $this->admin_role_gate();

        $acls = config('acl');

        $adminRole = AdminRole::find($id);
        return view('admin.admin_role.edit',compact('adminRole','acls'));

    }

    public function update($id,AdminRoleRequest $adminRoleRequest){

        $this->admin_role_gate();

        $adminRole = AdminRole::find($id);

        $adminRole->update($adminRoleRequest->all());

        return Redirect('admin/admin_role');

    }

    public function destroy($id){

        $this->admin_role_gate();

        $adminRole = AdminRole::find($id);

        $adminRole->delete();

        return Redirect('admin/admin_role');
    }
}
